﻿using System;
using System.Linq;

namespace DreamDriven.ObjectModel.Mvp
{
    /// <summary>
    /// Bindes Presenter to View
    /// </summary>
    public static class PresenterBinder
    {
        /// <summary>
        /// Binds the specified view. 
        /// </summary>
        /// <param name="view">The view.</param>
        public static void Bind(IView view)
        {
            var bindingAttribures = from attr in view.GetType().GetCustomAttributes(true)
                                    where attr is PresenterBindingAttribute
                                    select attr;
            foreach (PresenterBindingAttribute bindingAttribute in bindingAttribures)
            {
                Activator.CreateInstance(bindingAttribute.PresenterType, view);
                bindingAttribute.ViewType = view.GetType();
            }
        }
    }
}
